import static javax.swing.JSplitPane.HORIZONTAL_SPLIT
import static javax.swing.JSplitPane.VERTICAL_SPLIT
import com.google.api.translate.Language
import java.awt.Insets

frame = application(title: 'easy-translate',
        size:[320,480],
        pack: true,
        location:[50,50],
        locationByPlatform: true,
        iconImage: imageIcon('/griffon-icon-48x48.png').image,
        iconImages: [imageIcon('/griffon-icon-48x48.png').image,
                imageIcon('/griffon-icon-32x32.png').image,
                imageIcon('/griffon-icon-16x16.png').image]
) {

    splitPane(orientation: VERTICAL_SPLIT) {

        busyComponent(busy: bind{model.busy}) {
            scrollPane() {
                textbox = textArea(text:bind(target:model, targetProperty:'textSource'),
                    columns:40, rows:10, lineWrap: true, 
                    keyReleased: { e -> if (e.keyCode==10) { controller.action(e) } })
            }
        }

        panel() {
            borderLayout()
            splitPane(orientation: HORIZONTAL_SPLIT, constraints: CENTER) {
                busyComponent(busy: bind{model.result1Busy}) {
                    panel() {
                        borderLayout()
                        scrollPane(constraints:CENTER) {
                            lang1Box = textArea(editable: false, text:bind {model.lang1Result}, columns:20, rows:10, lineWrap: true)
                        }
                        comboBox(constraints:SOUTH,
                            items: Language.values().findAll { it != Language.AUTO_DETECT }.collect { it.name() } ,
                            selectedItem: bind(target: model, 'language1', value: model.language1) 
                        )
                    }
                }
                busyComponent(busy: bind{model.result2Busy}) {
                    panel() {
                        borderLayout()
                        scrollPane(constraints:CENTER) {
                            lang2Box = textArea(editable: false, text:bind {model.lang2Result}, columns:20, rows:10, lineWrap: true)
                        }
                        comboBox(constraints:SOUTH,
                            items: Language.values().findAll { it != Language.AUTO_DETECT }.collect { it.name() } ,
                            selectedItem: bind(target: model, 'language2', value: model.language2)
                        )
                    }
                }
            }
            panel(constraints: SOUTH) {
                borderLayout()
                
                panel(constraints: EAST) {
                    button(icon: imageIcon('/down.png'),  actionPerformed:{[textbox, lang1Box, lang2Box].each { it.decreaseFont() }}, margin: new Insets(0,0,0,0))
                    button(icon: imageIcon('/up.png'),    actionPerformed:{[textbox, lang1Box, lang2Box].each { it.increaseFont() }}, margin: new Insets(0,0,0,0))
                }
            }
        }
    }

    systemTray {
        trayIcon(id: "trayIcon",
                resource: "/griffon-icon-48x48.png",
                class: groovy.ui.Console,
                toolTip: "Double click to show/hide",
                actionPerformed: { frame.visible = !frame.visible }) {
        }
    }    
}

